<template>
  <header>
    <div class="adverContainer">
      <img src="@/assets/img/im/laoshi.png" alt="" />
      <span>{{ adminTitle }}</span>
    </div>
    <div class="baseMsg">
      <div class="im_msg_welcome">
        <el-input
          v-model="welcome"
          placeholder="请输入"
          size="small"
          style="width: 300px"
          @change="welcome_change"
        >
          <div slot="prepend">欢迎语</div>
        </el-input>
      </div>
      <span>及时收到提醒，请保持本页面不关闭</span>
    </div>
    <div class="otherMsg">
      <span @click="reflashData">
        <i class="el-icon-refresh-right"> </i>
        <small>更新</small>
      </span>
      <!-- <span @click="tonewurl('/index/page/robot', '机器人')">
        <i class="el-icon-coordinate"> </i>
        <small>机器人</small>
      </span>
      <span @click="tonewurl('/index/page/immaterial', '素材')">
        <i class="el-icon-s-tools"> </i>
        <small>素材</small>
      </span> -->
    </div>
  </header>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {
      welcome: "",
      info: {},
    };
  },
  mounted() {
    this.getHeaderData();
    this.get_welcome();
  },
  computed: {
    ...mapState({
      adminTitle: (state) => state.adminTitle,
    }),
  },
  methods: {
    tonewurl(url, title) {
      this.$store.commit("setId", "787");
      this.$store.commit("setParentTtile", "IM");
      sessionStorage.setItem("parentTitle", "IM");
      this.$store.commit("setTitle", title);
      sessionStorage.setItem("title", title);
      this.$store.commit("setbreadcrumbs", []);
      this.$router.push(url);
      this.$store.commit("showTitle2", false);
    },
    get_welcome() {
      this.$api.getim.get_welcome({}).then((res) => {
        if (res.data.code == 200) {
          this.welcome = res.data.result;
        }
      });
    },
    welcome_change() {
      this.$api.getim.edit_welcome({ welcome: this.welcome }).then((res) => {
        if (res.data.code == 200) {
          this.$fnc.alertSuccess("操作成功");
          // this.getUserInfo(this.sel_user);
        } else {
          this.$fnc.alertError("操作失败");
          // this.getUserInfo(this.sel_user);
        }
      });
    },
    async getHeaderData() {
      let res = await this.$api.getIndex.getIndexNew();
      if (res.data.code == 200) {
        this.info = res.data.result.mail;
      }
    },
    async reflashData() {
      let params = {};
      params.types = "mail";
      let res = await this.$api.getIndex.refreshIndexNew(params);
      if (res.data.code == 200) {
        this.$message({
          message: "更新成功",
          type: "success",
        });
        this.info = res.data.result;
      }
    },
  },
};
</script>

<style lang="less" scoped>
header {
  width: 100%;
  height: 100px;
  // background: linear-gradient(to right, rgb(71, 157, 242), rgb(57, 145, 239));
  background: url("../../../assets/img/im/headerImg.jpg");
  background-size: cover;
  display: flex;
  color: #fff;
  .adverContainer {
    width: 300px;
    height: 100%;
    font-size: 16px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding: 5px 0 5px 20px;
    img {
      width: 50px;
      height: 50px;
      border-radius: 5px;
    }
    > span {
      margin: 0 10px;
    }
  }
  .baseMsg {
    color: #fff;
    width: 840px;
    height: 100%;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding-left: 10px;

    span {
      font-size: 13px;
      color: rgb(172, 210, 254);
      padding-left: 20px;
    }
    .im_msg_welcome {
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
  .otherMsg {
    flex: 1;
    display: flex;
    flex-flow: row;
    justify-content: flex-start;
    align-items: center;

    > span {
      margin: 0 10px;
      display: flex;
      align-content: center;
      justify-content: center;
      cursor: pointer;
      i {
        font-size: 20px;
      }
      small {
        font-size: 12px;
        padding-left: 2px;
      }
    }
  }
}
</style>